﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace DungeonGenerator.Tests
{
    using System.Linq;

    using FluentAssertions;

    [TestClass]
    public class Vector2DTests
    {
        [TestMethod]
        public void WalkXNegative()
        {
            var v = new Vector2d{ x=0, y = 0, xMod = -6, yMod = 6};
            foreach (var vi in v.WalkX())
            {
                var xMin = Math.Min(v.x, v.x + v.xMod);
                var xMax = Math.Max(v.x, v.x + v.xMod);
                vi.X.Should().BeInRange(xMin,xMax);
                vi.Y.Should().Be(v.y);
            }
        }

        [TestMethod]
        public void WalkX()
        {
            var v = new Vector2d { x = 0, y = 0, xMod = 6, yMod = 6 };
            var min = Math.Min(v.x, v.x + v.xMod);
            var max = Math.Max(v.x, v.x + v.xMod);
            foreach (var vi in v.WalkX())
            {
                
                vi.X.Should().BeInRange(min, max);
                vi.Y.Should().Be(v.y);
            }
        }

        [TestMethod]
        public void WalkY()
        {
            var v = new Vector2d { x = 0, y = 0, xMod = -6, yMod = 6 };
            var min = Math.Min(v.y, v.y + v.yMod);
            var max = Math.Max(v.y, v.y + v.yMod);
            foreach (var vi in v.WalkY())
            {
                vi.Y.Should().BeInRange(min, max);
                vi.X.Should().Be(v.x);
            }
        }

        [TestMethod]
        public void Walk8By8()
        {
            var v = new Vector2d { x = 0, y = 0, xMod = 8, yMod = 8 };
            var points = v.Walk().ToArray();
            points.Length.Should().Be(64);
            foreach (var vi in v.Walk())
            {
                vi.X.Should().BeInRange(0, 7);
                vi.Y.Should().BeInRange(0, 7);
            }
        }

        [TestMethod]
        public void GetRectTest()
        {
            var v = new Vector2d { x = 0, y = 0, xMod = 8, yMod = 8 };
            var rect = v.GetRect();
            rect.X.Should().Be(Math.Min(v.x, v.x + v.xMod));
            rect.Y.Should().Be(Math.Min(v.y, v.y + v.yMod));
            rect.Right.Should().Be(Math.Max(v.x, v.x + v.xMod));
            rect.Bottom.Should().Be(Math.Max(v.y, v.y + v.yMod));
        }

    }
}
